package com.ydm.myapp001.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatDialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.Button;
import android.widget.Toast;

import com.ydm.myapp001.R;

/**
 * Created by highsixty on 2018/3/14.
 * mail  gaolulin@sunmi.com
 */

public class GoodsDetailDialog extends AppCompatDialogFragment implements View.OnClickListener {

    private static final String TAG = "MySelf_GoodsDialog";
    boolean isShow = false;//防多次点击

    private Button tvAddShopCart;

    public GoodsDetailDialog() {
        super();
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        Log.d(TAG, "onStart: ");
        super.onStart();
        Dialog dialog = getDialog();
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: ");
        View view = inflater.inflate(R.layout.dialog_goods_detail_layout, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onViewCreated: ");
        super.onViewCreated(view, savedInstanceState);
        initData();
        initView(view);
        initAction();
        initUI();
    }


    private void initView(View view) {
        tvAddShopCart = (Button) view.findViewById(R.id.bt_add_cart);
    }

    private void initAction() {
        tvAddShopCart.setOnClickListener(this);
    }

    private void initUI() {

    }

    private void initData() {

    }




    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_add_cart: //加入购物车
                SureTipDialog sureTipDialog = new SureTipDialog(getContext(), "提示", "你确定要加入购物车吗", true,  null);
                sureTipDialog.show();
                break;
            default:
                break;
        }
    }



    @Override
    public void show(FragmentManager manager, String tag) {
        if (isShow) {
            return;
        }
        super.show(manager, tag);
        isShow = true;
    }

    @Override
    public void dismiss() {
        super.dismiss();
        isShow = false;
    }
}
